home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0207_Parse Commandline.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1997-03-04  |  848 b   |  41 lines

  1. Most command line programs and some Windows programs has the
  2. ability to look for and handle parameters passed to it such as /? /HELP
  3. /Q. If you want to add the same capability to your Delphi programs, you
  4. can start with a function like this:
  5.  
  6. program cmdline;
  7. uses
  8.   SysUtils;
  9.  
  10. function CmdLineParamFound(sParamName : String ) : Boolean;
  11.  const
  12.  c_token = '/';
  13.  var
  14.  i     : integer;
  15.  sTemp : string;
  16.  
  17. begin
  18.  result := False;
  19.  for i := 1 to ParamCount do
  20.      begin
  21.      sTemp := ParamStr( i );
  22.      if( c_token = sTemp[ 1 ] )then
  23.      begin
  24.      if( ( c_token + UpperCase( sParamName ) ) =
  25.      UpperCase( sTemp ) )then
  26.      begin
  27.      result := True;
  28.      exit;
  29.      end;
  30. end;
  31. end;
  32. end;
  33.  
  34. begin
  35.   if( CmdLineParamFound( 'HELP' ) )then
  36.       begin
  37.      //
  38.      // display help here...
  39.      //
  40.      end;
  41. end.